<?php
//数组排序
function array_sort($arr,$keys,$type='asc'){ 
	foreach ($arr as $k=>$v){
		$keysvalue[$k] = $v[strtolower($keys)];
	}
	if(strtolower($type) == 'asc'){
		asort($keysvalue);
	}else{
		arsort($keysvalue);
	}
	reset($keysvalue);
	foreach ($keysvalue as $k=>$v){
		$new_array[$k] = $arr[$k];
	}
	return $new_array; 
}

 
//pw 2014/1/23 递归显示指定栏目的子栏目
/**
 * @para catid			要显示子栏目的根栏目ID
 * @para curid			当前选中的栏目ID
 * @para self			是否显示根栏目自身
 * @para self			要显示的字数
 */
 
function pwCateTree($catid=0,$curid=0,$self=false,$cut=15){
	$CATEGORYS=getcache('category_content_1','commons');
	if($self)$html='<ul><li class="parent"><a class="'.($catid==$curid?'current':'').'" rel="'.$catid.'" href="'.$CATEGORYS[$catid]['url'].'" title="'.$CATEGORYS[$catid]['catname'].'">'.str_cut($CATEGORYS[$catid]['catname'],$cut,'').'</a>';
	$html.=_pwSubCateTree(is_numeric($catid)?$catid:0,$CATEGORYS,$curid,$cut);
	$html.='</ul>';
	echo $html;
} 

//pw 2014/1/23 私用，请勿直接调用

function _pwSubCateTree($catid,$CATEGORYS,$curid,$cut){
	$html='<ul id="sub-'.$catid.'">';
	if($catid){
		foreach($CATEGORYS as $cid => $citem){
			if($citem['parentid']==$catid)$catList[]=$cid;
		}
	}else{
		$catList=array_keys($CATEGORYS);
	}
	foreach($catList as $cid){
		$html.='<li class="'.($CATEGORYS[$cid]['child']?'parent':'child').'"><a '.$cid.'='.$curid.' class="'.(($cid==$curid)?'current':'').'" rel="'.$cid.'" href="'.$CATEGORYS[$cid]['url'].'" title="'.$CATEGORYS[$cid]['catname'].'">'.str_cut($CATEGORYS[$cid]['catname'],$cut,'').'</a>';
		if($CATEGORYS[$cid]['child']){
			$html.=_pwSubCateTree($cid,$CATEGORYS,$curid,$cut);
		}
		$html.='</li>';
	}
	$html.='</ul>';
	return $html;
}
 
?>